﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using LotteryAdmin.AdminService;
namespace LotteryAdmin
{
    public partial class LotteryAdd : ChildWindow
    {
        LotteryAdminClient srv;
        public LotteryAdd()
        {
            InitializeComponent();
            srv = WcfProxy.GetProxy;
            this.Loaded += new RoutedEventHandler(LotteryAdd_Loaded);
            this.dataForm1.Loaded += new RoutedEventHandler(dataForm1_Loaded);
            srv.AddLotteryCompleted += new EventHandler<AddLotteryCompletedEventArgs>(srv_AddLotteryCompleted);
        }

        void srv_AddLotteryCompleted(object sender, AddLotteryCompletedEventArgs e)
        {
            if (e.Result)
            {
                MessageBox.Show("新增彩种成功!");
                this.DialogResult = true;
            }
            else
                MessageBox.Show("新增彩种失败!");
        }

        void dataForm1_Loaded(object sender, RoutedEventArgs e)
        {

        }

        void LotteryAdd_Loaded(object sender, RoutedEventArgs e)
        {
            this.dataForm1.CurrentItem = new LotteryInfo();
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.dataForm1.ValidateItem())
            {
                LotteryInfo info = this.dataForm1.CurrentItem as LotteryInfo;
                if (!Validate.ValidateUserIDModify(info.LotteryName))
                {
                    MessageBox.Show("彩种名称只接受数字、汉字、字母、下划线组合");
                    return;
                }
                info.IsEnable = Convert.ToInt32(((this.dataForm1.FindNameInContent("cbx_isEnable") as ComboBox).SelectedItem as ComboBoxItem).Tag.ToString());
                info.IsOpen = Convert.ToInt32(((this.dataForm1.FindNameInContent("cbx_isOpen") as ComboBox).SelectedItem as ComboBoxItem).Tag.ToString());
                info.Orientation = Convert.ToInt32(((this.dataForm1.FindNameInContent("cbx_orientation") as ComboBox).SelectedItem as ComboBoxItem).Tag.ToString());
                info.LotteryID = 3;
                srv.AddLotteryAsync(info);
            }
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }
    }
}

